package com.zcx.qshop.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zcx.helper.view.rebound.ReboundLayout;
import com.zcx.helper.view.rebound.ReboundListView;
import com.zcx.helper.widget.AppReboundAdapter;
import com.zcx.qshop.R;
import com.zcx.qshop.activity.ConfirmOrderActivity;
import com.zcx.qshop.conn.JsonCouponAsyGet;
import com.zcx.qshop.view.CouponView;

import java.util.List;

/**
 * Created by Administrator on 2015/8/22 0022.
 */
public class CouponAdapter extends AppReboundAdapter<JsonCouponAsyGet.Info.Coupon> {

    private LayoutInflater layoutInflater;

    public CouponAdapter(Context context,ReboundListView reboundListView,  List<JsonCouponAsyGet.Info.Coupon> objects) {

        super(context, reboundListView, objects);

        layoutInflater = ((Activity)context).getLayoutInflater();

    }

    @Override
    public ReboundLayout getReboundLayout(int i, ReboundLayout reboundLayout, ViewGroup viewGroup) {

        JsonCouponAsyGet.Info.Coupon coupon = getItem(i);

        CouponView couponView;

        if(reboundLayout == null){

            reboundLayout = (ReboundLayout) layoutInflater.inflate(R.layout.item_coupon, null);

            reboundLayout.setTag(couponView = (CouponView) reboundLayout.findViewById(R.id.item_coupon_coupon_view));

        }else{

            couponView = (CouponView) reboundLayout.getTag();

        }

        if (ConfirmOrderActivity.onOrderChangeListener != null) {

            couponView.setVisibility(View.GONE);

            couponView.setLoad(coupon.price, coupon.fullprice, coupon.endtime, coupon.statue.equals("-1"));

        }else{

            couponView.setLoad(coupon.price, coupon.fullprice, coupon.endtime ,coupon.statue.equals("-1"));

            couponView.setVisibility(View.VISIBLE);

        }

        return reboundLayout;

    }

}
